#coding：utf-8
from mySQL import do
#
# import datetime
# def obj_to_dict(obj):
#     dict = []
#     if(hasattr(obj, '__dict__')):
#         dict = obj.__dict__
#         for name in dict:
#             if(hasattr(dict[name], '__dict__')):
#                 dict[name]=obj_to_dict(dict[name])
#         return dict
#     elif(isinstance(obj, tuple)):
#         li = []
#         for item in obj:
#         	li.append(obj_to_dict(item))
#         return li
#     elif(isinstance(obj,datetime.datetime)):
#         return obj.strftime("%Y-%m-%d %H:%M:%S")
#     return obj
#
# class Users:
#     def __init__(self, d_id):
#         sqlUsers = do.deviceUser(d_id)
#         ids, names = [], []
#         for item in sqlUsers:
#             ids.append(item[0])
#             names.append(item[1])
#         self.id = ids
#         self.name = names
#
# class Sensors:
#     def __init__(self, d_id): # id, name,value,min,max,unit
#         sqlSensors = do.sensorByDid(d_id)
#         ids, names,units,mins,maxs = [],[],[],[],[]
#         for item in sqlSensors:
#             ids.append(item[0])
#             names.append(item[1])
#             units.append(item[5])
#             mins.append(item[3])
#             maxs.append(item[4])
#         self.id = ids
#         self.name = names
#         self.unit = units
#         self.min = mins
#         self.max = maxs
#
# class DeviceAllMessage:
#     def __init__(self, d_id):
#         detail = do.device_detail(d_id);
#         if(detail == None):
#             return None;
#         self.id = detail[0]
#         self.name = detail[1]
#         self.type = detail[2]
#         self.address = detail[3]
#         self.state = detail[4]
#         self.description = detail[5]
#         self.users = Users(d_id)
#         self.sensor = Sensors(d_id)

# if __name__ == '__main__':
#     msg  = DeviceAllMessage(2)
#     print(obj_to_dict(msg))
#     historyData = do.historyByDid(1, 1, 1)
#     print(obj_to_dict(historyData))